package com.yanmaohu.nikita.scanner;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Bright Lee
 */
public enum TokenType {

    EOF(),

    ID(),

    CHARACTER_LITERAL(),
    INTEGER_LITERAL(),
    STRING_LITERAL(),

    USE("use"),
    TRUE("true"),
    FALSE("false"),
    CASE("case"),
    WHEN("when"),
    ELSE("else"),
    CONTINUE("continue"),
    BREAK("break"),
    RETURN("return"),
    FOR("for"),
    DO("do"),
    WHILE("while"),
    MUTABLE("mutable"),
    NATIVE("native"),
    PROTECTED("protected"),
    PUBLIC("public"),
    GOTO("goto"),

    PLUS("+"),
    MINUS("-"),
    MUL("*"),
    DIV("/"),
    REM("%"),
    EXP("^"),

    ASSIGN("="),
    ADD_ASSIGN("+="),
    SUB_ASSIGN("-="),
    MUL_ASSIGN("*="),
    DIV_ASSIGN("/="),
    REM_ASSIGN("%="),
    EXP_ASSIGN("^="),
    BIT_AND_ASSIGN("&="),
    BIT_OR_ASSIGN("|="),
    INC_ASSIGN("++"),
    DEC_ASSIGN("--"),
    AND_ASSIGN("&&="),
    OR_ASSIGN("||="),

    AND("&&"),
    OR("||"),
    NOT("!"),
    EQ("=="),
    NE("!="),
    LT("<"),
    LE("<="),
    GT(">"),
    GE(">="),

    BIT_AND("&"),
    BIT_OR("|"),
    BIT_INVERT("~"),
    LEFT_SHIFT("<<"),
    RIGHT_SHIFT(">>"),
    AM_RIGHT_SHIFT(">>>"),

    LEFT_PAR("("),
    RIGHT_PAR(")"),
    LEFT_BRK("["),
    RIGHT_BRK("]"),
    LEFT_BRC("{"),
    RIGHT_BRC("}"),

    COMMA(","),
    PERIOD("."),
    QUEST("?"),
    COLON(":"),
    TYPE_LIMIT("::"),
    FORCE_TYPE_CONVERT(":::"),
    SEMICOLON(";");

    private static final Map<String, TokenType> MAP = new HashMap<>();
    static {
        TokenType[] tokenTypes = values();
        for (TokenType tokenType : tokenTypes) {
            String content = tokenType.content;
            if (content == null) {
                continue;
            }
            MAP.put(content, tokenType);
        }
    }
    public static TokenType getTokenType(String content) {
        return MAP.get(content);
    }

    private String content;

    TokenType(String content) {
        this.content = content;
    }

    TokenType() {
        this(null);
    }

    public String content() {
        return content;
    }

}
